Skip to content

fix(libkernel_sys): read and write the aiocb of aio_read, aio_write and aio_fsync as FreeBSD's aio_aqueue does - #14403

Merged
oneandonlydean merged 6 commits into
boykopovar:mainfrom
roboterspinne:fix/libkernel-sys-aio-aiocb-copy
Nov 7, 2026
Merged

oneandonlydean merged 6 commits into
boykopovar:mainfrom
roboterspinne:fix/libkernel-sys-aio-aiocb-copy

Conversation

@roboterspinne

@roboterspinne roboterspinne commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What

On 26fa121 (line numbers below refer to it) aio_read, aio_write and aio_fsync go to Queue() (core/libs/prx/libkernel_sys/Aio.cpp:208-219), which handles only a null aiocb (line 152), then stores status, error and kernelinfo straight into the guest aiocb (156-158, 160, 182, 184) and copies it with const GuestAiocb request = *user; (164); Consume() (133-140), reached from aio_return and aio_waitcomplete, stores error and status the same way. An aiocb at a bad address such as 0x10, an aiocb in a read-only page, or a completed request whose aiocb became read-only therefore crashes the host process (FATAL: unhandled exception 0xc0000005, exit 139) instead of failing. FreeBSD 11.4's aio_aqueue sets up the process's aio state first (1466-1467), makes the first status/error/kernelinfo stores without checking them (1471-1473), checks the queue limit for EAGAIN (1475-1479), copies the aiocb in and fails with EFAULT when that faults (1484-1489), fails with EINVAL without queuing when the kernelinfo store faults after the descriptor, opcode and offset checks (1576-1580), and ignores the EINPROGRESS store (1609) and the error store at aqueue_fail (1650); kern_aio_return and kern_aio_waitcomplete store error and status with suword and ignore the result. The library's debt entry (docs/dev/debt/libkernel_sys.md:357) already says the aio rules follow FreeBSD 11 vfs_aio.c, and the existing check aio_read(nullptr) gives EFAULT (core/libs/tests/GuestKernelSysAio.cpp:76) already encodes the copy-in rule, for null only.

Tested

Windows 11, WinLibs GCC 15.2.0, Ninja, Release, BUILD_TESTING=ON, on 28af4b5 (based on 26fa121):

  • cmake --build build --parallel 6 --target guest_kernel_sys_aio_tests, then build/tests/guest_kernel_sys_aio_tests.exe with build/core/libs/libs/unpatched and the WinLibs bin first on PATH. On untouched 26fa121 the test without the new checks prints guest_kernel_sys_aio passed (0.32 s).
  • Counter-check: with the new test file and the untouched Aio.cpp, each new check fails.
    • The 0x10 check: FATAL: unhandled exception 0xc0000005, rip ... libkernel_sys.prx+0x1301f, write of 0x0000000000000058, exit 139.
    • With the earlier new checks left out, the straddling aiocb: check failed at line 123 (the straddling check; the variant file is one line shorter), exit 1: the old code does not fault there, but the call's result is not -1/EFAULT with status -1 and error EFAULT.
    • The read-only aiocb: write of 0x...2048 at libkernel_sys.prx+0x1301f, exit 139.
    • The completed request made read-only: write of 0x...3038 at libkernel_sys.prx+0x123ed (in Consume), exit 139.
  • With this change: guest_kernel_sys_aio passed, exit 0, 0.19 s; 10 consecutive runs all passed. ctest --test-dir build -R '^guest_kernel_sys_aio$': 1/1 passed.
  • Follow-up commit a59f3d9 changes only how Store forms the field address (a pointer to the member and integer arithmetic instead of &user->field); the order and every result stay the same. On a59f3d9, cmake --build build --parallel 6 --target guest_kernel_sys_aio_tests, then ctest --test-dir build -R '^guest_kernel_sys_aio$' --output-on-failure: 1/1 passed (0.14 s), which includes the null aiocb check aio_read(nullptr) -> -1/EFAULT at line 117 of core/libs/tests/GuestKernelSysAio.cpp.
  • Not run: a UBSan build of the project (WinLibs GCC has no libubsan). The Store shape was checked with a stand-alone probe built with -fsanitize=undefined -fno-sanitize=vptr -fsanitize-trap=all (GCC 15.2.0): the shape of 28af4b5 traps on a null aiocb (Illegal instruction, exit 132), the shape of a59f3d9 returns -1 without a trap.
  • Merge of main b28bb77 into this branch (2dbd3cd; the debt-file conflict with the merged feat(libkernel_sys): create symlink targets with parent-directory components #10625 is resolved by keeping both entries, and main's change to the AIO waits in Aio.cpp and its test, adef563, merges without conflict): cmake --build build --parallel 6 --target guest_kernel_sys_aio_tests, then ctest --test-dir build -R '^guest_kernel_sys_aio$' --output-on-failure: 1/1 passed (0.23 s).
  • Merge of main 4f41f4c into this branch (aeaf5fd; no conflicts, and among this branch's files main changed only docs/dev/debt/libkernel_sys.md since b28bb77): cmake --build build --parallel 6 --target guest_kernel_sys_aio_tests, then ctest --test-dir build -R '^guest_kernel_sys_aio$' --output-on-failure: 1/1 passed (0.13 s). The hosted Windows job at aeaf5fd (job 125879104155) runs it: 1/1 Test #654: guest_kernel_sys_aio ... Passed 0.34 sec. The job at 2dbd3cd built the test but ran conventions_git_errors (Test feat(relinker): lower register-form EXTRQ and relocate following instructions for short sites #54), because main then lacked fix(tools): end the CTest index file with a newline so the Windows pull request job runs the last selected guest test #14413 and the CTest index file lost its last digit.
  • python tools/check_conventions.py --base 4f41f4c375 --head HEAD with this title and description passed.
  • Not run: the Linux and macOS checked-copy paths (process_vm_writev/mprotect and mach_vm_write), since there is no such host here.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The aio change reads correctly from source, but the NULL-pointer rejection in Queue was removed and no test covers a NULL request; approval waits for the hosted Windows run at 28af4b5e97.

What I ran

Exact head 28af4b5e97bfe4b9dd59a826c000d51946e91d0e; PR base b2620e56d114ef053f8b45433b1d48aff7ec37ba, unchanged at completion. No build and no test run. Commands:

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14403
python3 tools/pr_abi_audit.py --base b2620e56d114ef053f8b45433b1d48aff7ec37ba --head 28af4b5e97bfe4b9dd59a826c000d51946e91d0e --json
python3 tools/pr_test_quality.py --root <git archive of 28af4b5e97: core/libs/tests, core/libs/prx/libkernel_sys, core/libs/prx/libc, core/libs/CMakeLists.txt> --json core/libs/tests/GuestKernelSysAio.cpp

The precheck's ABI and test-quality helpers were missing from the isolated head tree, so I ran both by hand from /marc/AnyPS5/tools.

Results

Check Result
Diff check, conventions and PR template (precheck) Passed
Live dependency and mergeability (precheck) Passed
ABI audit (by hand) Passed, 0 findings; lexical only
Test-quality heuristic (by hand) One possible-unregistered-cpp-test finding for GuestKernelSysAio.cpp; false positive, because CMake registers guest_kernel_sys_aio_tests at core/libs/CMakeLists.txt L1144
Hosted conventions and labels Success
Hosted Windows Not complete at review time
Hosted relinker and Linux Skipped or not applicable to this change

Findings

Blocking: none.

Non-blocking:

  1. Queue in Aio.cpp no longer rejects a NULL user before it takes the lock and sets aio.used = true (Aio.cpp L156-L162 at this head). The Store(&user->status, ...) calls then form &user->status from a null pointer, which is undefined behaviour in C++ and a null member access that UBSan reports. A NULL request still ends in EFAULT, because GuestCopyIn_nid_no_patch returns false for a zero source address (General.cpp L856-L861 at this head). The new test only passes address 0x10, so the NULL path is not pinned. Suggested fix: restore if (user == nullptr) return Fail(GuestEfault); before the lock, and add a NULL case that asserts EFAULT and an unchanged aio.used.

Sources

Not verified

  • No build and no run of guest_kernel_sys_aio_tests on any platform; the hosted Windows run at this head was not complete at review time.
  • The NULL behaviour was reasoned from source, not executed.
  • Console behaviour of aio_read, aio_write and aio_fsync is not checked here.

To get this to a good state

The NULL-pointer suggestion above is non-blocking. The remaining gate is the hosted Windows run at 28af4b5e97; the same checks will be rerun if the head changes.

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 16191 core/libs/prx/libkernel_sys/Aio.cpp L164-165
PR 16328 docs/dev/debt/libkernel_sys.md L385

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 9161 docs/dev/debt/libkernel_sys.md
PR 9162 docs/dev/debt/libkernel_sys.md
PR 9297 docs/dev/debt/libkernel_sys.md
PR 9302 docs/dev/debt/libkernel_sys.md
PR 10657 docs/dev/debt/libkernel_sys.md
PR 12130 docs/dev/debt/libkernel_sys.md
PR 12642 docs/dev/debt/libkernel_sys.md
PR 14212 docs/dev/debt/libkernel_sys.md
PR 15037 docs/dev/debt/libkernel_sys.md
PR 15111 docs/dev/debt/libkernel_sys.md
PR 16149 docs/dev/debt/libkernel_sys.md
PR 16152 docs/dev/debt/libkernel_sys.md
PR 16215 docs/dev/debt/libkernel_sys.md
PR 16370 docs/dev/debt/libkernel_sys.md

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The aio change is correct at 28af4b5e97, and the hosted Windows run for this exact head passed guest_kernel_sys_aio_tests, which was the remaining gate in my earlier comment.

What I ran

Exact head 28af4b5e97bfe4b9dd59a826c000d51946e91d0e; PR base b2620e56d114ef053f8b45433b1d48aff7ec37ba, unchanged at completion. No build and no local test run. Commands:

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14403
python3 tools/pr_abi_audit.py --base b2620e56d114ef053f8b45433b1d48aff7ec37ba --head 28af4b5e97bfe4b9dd59a826c000d51946e91d0e --json

The precheck's ABI and test-quality helpers were missing from the isolated head tree; the ABI helper was run by hand from /marc/AnyPS5/tools.

Results

Check Result
Diff check, conventions and PR template (precheck) Passed
Live dependency and mergeability (precheck) Passed
ABI audit (by hand) Passed, 0 findings; lexical only
Test-quality heuristic (by hand) One path false positive; the test is registered at core/libs/CMakeLists.txt L1144
Hosted Windows, job at this head Success; guest_kernel_sys_aio_tests built and passed (1 of 1)
Unedited hosted log lines (Windows job)
[3/4] Linking CXX executable tests\guest_kernel_sys_aio_tests.exe
100% tests passed, 0 tests failed out of 1
guest_kernel_sys_aio_tests

Findings

Blocking: none.

Non-blocking: the NULL-pointer point in my earlier comment still applies. Queue no longer rejects a NULL user before taking the lock and setting aio.used, and no test pins the NULL case. The restored early return, or a NULL test case, would close it. This does not block approval.

Sources

Not verified

  • Hosted Linux was skipped for this change.
  • The NULL behaviour was reasoned from source, not executed.
  • Console behaviour of aio_read, aio_write and aio_fsync is not checked.

To get this to a good state

Nothing is required for the approval. The NULL-pointer suggestion is optional.

@roboterspinne

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Thanks for the review. Two points on the NULL note:

  1. Behaviour. The NULL path is pinned by the existing check aio_read(nullptr) -> -1/EFAULT at core/libs/tests/GuestKernelSysAio.cpp:117, which runs in Validation() after BeforeUse(). Taking the lock and setting aio.used before the stores and the copy-in is deliberate: FreeBSD's aio_aqueue calls aio_init_aioinfo first, then stores status, error and kernelinfo unchecked, checks the queue limit for EAGAIN, and only then copies the aiocb in, so a NULL aiocb marks the process's aio as used and a full queue reports EAGAIN before EFAULT. Restoring the early return would change both, so the order stays.

  2. Undefined behaviour. You are right that &user->status on a null user is a null member access. GCC reports it: a stand-alone probe of the Store shape built with -fsanitize=undefined -fno-sanitize=vptr -fsanitize-trap=all (GCC 15.2.0) traps on a null aiocb, and the nightly sanitizer build uses -fsanitize=undefined -fno-sanitize=vptr and runs guest_kernel_sys_aio. a59f3d9 changes Store to take the aiocb and a pointer to the member and to form the field's address as integer arithmetic from the aiocb pointer, so no member address is formed through a null pointer; the member pointer still ties the value to the field's type, and the order and every result are unchanged. guest_kernel_sys_aio passes on a59f3d9 (Windows 11, WinLibs GCC 15.2.0), and the Tested section is updated.

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ AMD GPU test: passed

PR head a59f3d9 merged onto main f2d874c · tested 2026-11-01 19:16 UTC · 12 min

GPU AMD Radeon RX 6300 (RADV NAVI24), driver Mesa 25.2.8-0ubuntu0.24.04.4, Vulkan 1.4.318
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-42-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 927 passed · 4 failed (0 new, 3 also fail on main, 1 unstable on main) · 4 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 935 of 3,168 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (456 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 120.0 s, ⚠️ public_headers 54.2 s, ⚠️ unwrap_self 36.7 s, ⚠️ agc_driver_image_sample_unnormalized 36.6 s, ⚠️ agc_driver_lazy_resolved_abi 34.9 s
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_pipeline_journal: failed in 3 of the last 5 main runs
Failing on main too (3, not counted against this PR)
agc_driver_image_table
agc_driver_native_depth_bda_clear
agc_driver_native_multisample_depth
Validation IDs already present on main (5 IDs in 389 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (389 tests): agc_driver_address_passes, agc_driver_alias_copy_label, agc_driver_alpha_to_coverage, agc_driver_array_layer_target, agc_driver_bc_block_copy, agc_driver_bda_anchor_reads, agc_driver_bda_span_reads, agc_driver_bindless_images, and 381 more
VUID-vkCmdCopyImage-srcImage-01548 (6 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-vkCmdCopyImage-srcImage-01551 (6 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
VUID-VkShaderModuleCreateInfo-pCode-08737 (1 test): agc_driver_image_sample_derivatives
Skipped (4)
agc_driver_copied_writer_label_order: skipped, the device reports a minStorageBufferOffsetAlignment of 4, so the dispatch binds its record at +0x1004 in place and nothing is written back; the test needs an alignment above 4
agc_driver_linear_target_direct_write_completion: skipped, the device does not keep host imports write-watched, so no completion stamp over the target is tracked
agc_driver_ngg_vertex_wave_reduction: skipped, s3 describes a 32-lane wave only on 32-lane subgroups, and the device has 64 lanes
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
Reproduce
git fetch origin a59f3d947c948fe756535f186c6f5ab1907c64ad f2d874c1fdccf781c0fa5d86619bb5dd8894b958
git checkout f2d874c1fdccf781c0fa5d86619bb5dd8894b958 && git merge --no-ff a59f3d947c948fe756535f186c6f5ab1907c64ad
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 12 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 16 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings from the read; the aio test was built on Windows but did not run

This PR changes aio_read, aio_write and aio_fsync so that the guest aiocb is read and written field by field, in the way FreeBSD's aio_aqueue does. The change goes through a Store helper that writes one field at its member offset with GuestCopyOut. I read the production change in full. The Windows CTest run built guest_kernel_sys_aio_tests.exe but did not select it, so the new behaviour has no hosted pass.

What I ran

  • Head a59f3d947c948fe756535f186c6f5ab1907c64ad; base b2620e56d114ef053f8b45433b1d48aff7ec37ba. 3 files, +79/-11: core/libs/prx/libkernel_sys/Aio.cpp (+27/-), core/libs/tests/GuestKernelSysAio.cpp (+61), and docs/dev/debt/libkernel_sys.md (one line).
  • Read the Aio.cpp change in full. The request path now copies the aiocb in with GuestCopyIn (EFAULT on failure) and writes kernelinfo, error and status through Store, which returns the copy-out result. The completion path writes error and status through Store but ignores the result. A failed kernelinfo store in the request path returns EINVAL.
  • Did not read the test bodies in GuestKernelSysAio.cpp.
  • Hosted, Windows: guest_kernel_sys_aio_tests.exe was built and linked. The CTest selection had one case, conventions_ci_gate (Test #52). No aio case ran.
  • Read-only checks from the trusted main checkout: diff check and conventions passed. ABI audit passed: 8 symbols. Stack check: clean, no declared dependencies, no errors.
  • Hosted, other jobs: library-portability and report succeeded. Linux, relinkers and write-watch skipped.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed stack check: clean; no declared dependencies
ABI audit (main-checkout tool) passed 8 symbols
guest_kernel_sys_aio_tests (hosted, Windows) built, not run linked, but not in the CTest selection
Aio.cpp change (read) passed by reading the field-by-field writes are as described; see the non-blocking notes
Test bodies in GuestKernelSysAio.cpp not verified not read
Negative controls not run no local build
Read-only check output

Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: passed (8 symbols). Stack check: clean, no declared dependencies, no errors. Hosted: gh api repos/boykopovar/AnyPS5/commits/a59f3d947c948fe756535f186c6f5ab1907c64ad/check-runs, and the Windows job log.

Negative control

Not run here. A negative control needs a Windows build and run of the aio test, and code from this head is not run here.

Findings

Blocking

None from the code read.

Non-blocking

  • The completion path ignores the result of Store when it writes error and status, while the request path checks its stores. If a copy-out fails when a job finishes, the guest is not told. The diff does not say whether that is intended.
  • A failed kernelinfo store in the request path returns EINVAL, and a failed copy-in returns EFAULT. The diff does not give the reason for the different codes.
  • Store takes member offsets from a static GuestAiocb through reinterpret_cast. It assumes the guest layout matches the member offsets. That assumption was not checked here.

Sources

Not verified

  • The test bodies in GuestKernelSysAio.cpp.
  • The aio behaviour at run time on Windows (no hosted case ran).
  • The guest layout assumed by Store.

To get this to a good state

  • Run guest_kernel_sys_aio_tests at this head in hosted CI. Say in the PR whether the completion-path copy-out result should be checked, and why the error codes differ.

@roboterspinne

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Thanks. On the three points:

  1. Hosted run: the Windows job built guest_kernel_sys_aio_tests and then ran only Test #52: conventions_ci_gate. That matches the bug that fix(tools): end the CTest index file with a newline so the Windows pull request job runs the last selected guest test #14413 fixes: build_changed_guest_tests.py writes the CTest index file without a final newline, and CTest drops its last character, so a selected index such as 520 becomes 52 (in my build tree guest_kernel_sys_aio is test test(shader): cover v_fmac_f32, v_fmamk_f32 and v_fmaak_f32 and count them as decoded #520). The test passes locally at this head (ctest --test-dir build -R '^guest_kernel_sys_aio$', 1/1, see Tested). A rerun after fix(tools): end the CTest index file with a newline so the Windows pull request job runs the last selected guest test #14413 is merged would run it in hosted CI.

  2. The completion path ignores the Store result on purpose: FreeBSD's kern_aio_return and kern_aio_waitcomplete store error and status with suword and ignore the result (vfs_aio.c 1852-1853 and 2447-2448, linked in the description). The request path follows aio_aqueue: a faulting copy-in fails with EFAULT (1484-1489), while a faulting kernelinfo store after the descriptor, opcode and offset checks fails with EINVAL without queuing the request (1576-1580). Both are in the first paragraph and the Rule of the description.

  3. Layout: Store takes the offset of the member in GuestAiocb, and that layout is pinned by the static_asserts at Aio.cpp:55-56 (lioOpcode at 48, status at 56, sigevent at 80, size 160).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 2, 2026
…io-aiocb-copy

# Conflicts:
#	docs/dev/debt/libkernel_sys.md
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 2, 2026

@XairRrR XairRrR left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — approved

aio_read, aio_write and aio_fsync now use checked copies to read and write the guest aiocb, in FreeBSD aio_aqueue order, and Consume makes its stores without checking the result. On Linux the PR merges and builds cleanly, the aio test passes, and with Aio.cpp reverted the test crashes.

What I ran

Head aeaf5fda38cb6d60046bdbfa55394004ee694bf0, main 4f41f4c375f5abb487dbd184fbc150f31994d762, merged tree a0b9f39c8f5bb2a10c572fa8314fa0198747d569. Debian 13, GCC 14.2.0, Release, Ninja, BUILD_TESTING=ON.

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...aeaf5fda38cb6d60046bdbfa55394004ee694bf0
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
ctest --test-dir build -R '^guest_kernel_sys_aio$' --output-on-failure --repeat until-fail:10
# negative control
git show 4f41f4c375f5abb487dbd184fbc150f31994d762:core/libs/prx/libkernel_sys/Aio.cpp > core/libs/prx/libkernel_sys/Aio.cpp
ninja -C build -j32 -l32 guest_kernel_sys_aio_tests
ctest --test-dir build -R '^guest_kernel_sys_aio$' --output-on-failure
git show a0b9f39c8f5bb2a10c572fa8314fa0198747d569:core/libs/prx/libkernel_sys/Aio.cpp > core/libs/prx/libkernel_sys/Aio.cpp
ninja -C build -j32 -l32 guest_kernel_sys_aio_tests
ctest --test-dir build -R '^guest_kernel_sys_aio$' --output-on-failure
git status --porcelain

Results

Check Result
git diff --check Clean
check_conventions.py All conventions checks passed
Build (script) Configure, build and libs succeeded
Selected tests (script) 862 ran, 859 passed, 2 expected skips, 0 new failures, 0 timeouts. The one failure, unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group, also fails on main and has nothing to do with this change
guest_kernel_sys_aio, 10 runs 10 of 10 passed, 0.10–0.20 s each
Negative control Fails (SEGFAULT)
Worktree after restore Clean; the test passes again
Negative control output
1/1 Test #647: guest_kernel_sys_aio .............***Exception: SegFault  0.01 sec
0% tests passed, 1 tests failed out of 1
	647 - guest_kernel_sys_aio (SEGFAULT)

Negative control

I restored core/libs/prx/libkernel_sys/Aio.cpp from main, kept the new test, then rebuilt libkernel_sys.prx and guest_kernel_sys_aio_tests. The test crashes with SIGSEGV on the first new check, the 0x10 aiocb (GuestKernelSysAio.cpp:120). Because the crash ends the run there, this control does not cover the three later new checks one by one. The description reports a separate counter-check for each of them on Windows.

After restoring the merged Aio.cpp and rebuilding, the test passes and git status --porcelain is empty.

Code review notes

  • I compared the order in Queue (core/libs/prx/libkernel_sys/Aio.cpp:158-202) with FreeBSD's aio_aqueue, using the description's quotes and line numbers. My reading of FreeBSD comes from memory; I could not open the source (see Not verified). The order matches:
    • aio.used is set first;
    • the first status, error and kernelinfo stores are unchecked;
    • a full queue gives EAGAIN before the copy-in;
    • a failed copy-in stores EFAULT and returns EFAULT;
    • a failed kernelinfo store gives EINVAL through the aqueue_fail-style error store, and the request is not queued;
    • the EINPROGRESS store is unchecked.
  • Consume (Aio.cpp:140-147) ignores the store results, which matches kern_aio_return and kern_aio_waitcomplete using suword without a check. This answers MarcZX10's question about why the completion path does not check its stores.
  • Store (Aio.cpp:94-99) computes the field offset from a static zero-initialised GuestAiocb and adds it to user as an integer. No member address is ever formed from a null user, which deals with MarcZX10's UB point. The layout is fixed by the static_asserts at Aio.cpp:55-56.
  • Null stays covered: GuestCopyIn_nid_no_patch rejects address 0 (core/libs/prx/libc/src/General.cpp:856-861), and the existing check at GuestKernelSysAio.cpp:119 passed in this run. I confirm the author's reply to MarcZX10's NULL point, now with an executed result.
  • On Linux, GuestCopyOut_nid_no_patch only succeeds when process_vm_writev copies every byte (General.cpp:839-847), so a partial write counts as a failure. The author could not run this Linux path; this run exercises it, including the straddling and read-only-page cases.
  • The debt entry change only adds the remaining gap (a bad pointer passed to aio_error, aio_suspend or aio_waitcomplete). The code backs this up: aio_error reads aiocb->status directly (Aio.cpp:235), and aio_waitcomplete writes *result (Aio.cpp:277). The change adds no code comments, and the checklist lines are all present.

Findings

Blocking

None.

Non-blocking

  • GuestKernelSysAio.cpp:123: the four pages from Pages(page * 4) are never unmapped (munmap/VirtualFree). This does no harm in a short-lived test process, but a matching release helper would keep the test tidy.

Not verified

  • The Windows (VirtualQuery plus HostWrite) and macOS (mach_vm_write) copy paths; only Linux ran here.
  • The three later new checks were not reverted one at a time here (see Negative control).
  • The FreeBSD vfs_aio.c line numbers were not opened here, because there is no network.
  • Console behaviour.
  • The script skipped the Vulkan validation comparison because the change touches no AGC, shader or VideoOut files; it does not apply to this change.

@roboterspinne

Copy link
Copy Markdown
Contributor Author

@MarcZX10 The hosted Windows job now runs guest_kernel_sys_aio (job 125879104155): 1/1 Test #654: guest_kernel_sys_aio ... Passed 0.34 sec, 100% tests passed, 0 tests failed out of 1. The new run checks out main 4f41f4c, which has #14413, so the CTest index keeps its last digit. The head is aeaf5fd, a merge of that main into 2dbd3cd without conflicts; main changed none of this branch's code files. The Tested section lists the merge and the job.

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ AMD GPU test: passed

PR head aeaf5fd merged onto main 4f41f4c · tested 2026-11-03 11:40 UTC · 15 min

GPU AMD Radeon RX 6300 (RADV NAVI24), driver Mesa 25.2.8-0ubuntu0.24.04.4, Vulkan 1.4.318
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-42-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 1,196 passed · 6 failed (0 new, 4 also fail on main, 2 unstable on main) · 6 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 1,208 of 3,811 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (574 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 120.2 s, ⚠️ public_headers 71.9 s, ⚠️ agc_driver_image_sample_unnormalized 43.5 s, ⚠️ agc_driver_lazy_resolved_abi 30.3 s
Unstable on main (2, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_pipeline_journal: failed in 7 of the last 9 main runs
agc_driver_store_over_untracked: failed in 1 of the last 9 main runs
Failing on main too (4, not counted against this PR)
agc_driver_image_table
agc_driver_native_depth_bda_clear
agc_driver_native_multisample_depth
agc_driver_submit_progress
Validation IDs already present on main (4 IDs in 489 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (489 tests): agc_driver_address_passes, agc_driver_alias_copy_label, agc_driver_alpha_to_coverage, agc_driver_array_layer_target, agc_driver_bc_block_copy, agc_driver_bda_anchor_reads, agc_driver_bda_span_reads, agc_driver_bindless_images, and 481 more
VUID-vkCmdCopyImage-srcImage-01548 (8 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth, agc_driver_stencil_null_feedback, agc_driver_stencil_plane_memory
VUID-vkCmdCopyImage-srcImage-01551 (8 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth, agc_driver_stencil_null_feedback, agc_driver_stencil_plane_memory
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (1 test): agc_driver_srgb8_color_target
Skipped (6)
agc_driver_copied_writer_label_order: skipped, the device reports a minStorageBufferOffsetAlignment of 4, so the dispatch binds its record at +0x1004 in place and nothing is written back; the test needs an alignment above 4
agc_driver_float16_unused_nan_payloads: skipped, the device has no native f16 conversions with RTE rounding and kept f16 denormals
agc_driver_linear_target_direct_write_completion: skipped, the device does not keep host imports write-watched, so no completion stamp over the target is tracked
agc_driver_ngg_vertex_wave_reduction: skipped, s3 describes a 32-lane wave only on 32-lane subgroups, and the device has 64 lanes
agc_driver_scattered_runs: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
Reproduce
git fetch origin aeaf5fda38cb6d60046bdbfa55394004ee694bf0 4f41f4c375f5abb487dbd184fbc150f31994d762
git checkout 4f41f4c375f5abb487dbd184fbc150f31994d762 && git merge --no-ff aeaf5fda38cb6d60046bdbfa55394004ee694bf0
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 12 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 16 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@oneandonlydean oneandonlydean self-assigned this Nov 5, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 5, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 5, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 7, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 7, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi @roboterspinne, thanks for the aiocb fix. We merged the latest main into your branch (merge commit b3a6473) to clear the conflict in docs/dev/debt/libkernel_sys.md: main had moved the Functional section further down the file, so your updated aio_read, aio_write, ... entry now sits at its new place there, word for word. Nothing else in your changes was touched. Thanks!

@oneandonlydean
oneandonlydean merged commit e887ebb into boykopovar:main Nov 7, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants